﻿<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- STYLESHEETS -->
		<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
		<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
		<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
		<link rel="stylesheet" type="text/css" href="../../css/responsive.css">

		<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
		<!-- file-input -->
		<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
		<!-- SELECT2 -->
		<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
		<!-- UNIFORM -->
		<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
		<!-- datatable -->
		<link rel="stylesheet" href="../../js/datatables/datatable.css">
		<!-- WIZARD -->
		<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />

	<!-- JQUERY -->
		<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
        <script src="../../js/common.js"></script>
	</head>

	<body>
		<header class="navbar clearfix" id="header">
		</header>

		<!-- PAGE -->
		<section id="page">
			<!-- SIDEBAR -->
			<div id="sidebar" class="sidebar">
				<div class="sidebar-menu nav-collapse">

					<!-- SIDEBAR MENU -->
					<ul>
						

					</ul>
					<!-- /SIDEBAR MENU -->
				</div>

			</div>
			<!-- /SIDEBAR -->
			<div id="main-content">
			<!-- 选择图片 -->
			<div class="modal fade" id="box-config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
					<form id="form_Images">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">选择图片</h4>
							</div>
							<div class="modal-body">
							<div class="form-group mrg-bt10">
							                   <label class="control-label col-sm-3" style="line-height:34px;">图片类型：</label>
															<div class="col-md-3">
																<select id="ImagesType_select" class="col-md-12 select2-offscreen" tabindex="-1">												
																		<option value="-1">选择类型</option>
																		<option value="QuantityCheck">质检报告</option>
																		<option value="Size">尺码</option>															
																		</select>	
															</div>	
															
															<div class="col-sm-1">
																<a class="btn btn-primary searchImages">查询</a>
															</div>		
															<div style="line-height:34px;color:red;margin-left:20px" class="col-sm-4">图片可点击查看大图</div>					
															</div>
															<div class="form-group mrg-bt10" style="height:auto;">
															<table id="db_Images_list" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
																			
															</table>
															</div>
								
							</div>
							
						</div>
						</form>
						
					</div>
				</div>
				
			<!-- end -->
<!-- SAMPLE BOX CONFIGURATION MODAL FORM-->
			<div class="modal fade" id="editImage" tabindex="-1" role="dialog"
				aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<form id="form_focus">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">维护图片</h4>
							</div>
							<div class="modal-body">
							
								<div class="form-group  mrg-bt10" style="height: 100px">
									<label class="control-label col-md-3" style="line-height: 34px;">
										<span class="required">*</span>
										图片：
									</label>
									<form>
										<div class="col-md-8">
											<div hidden-image></div>
											<div class="fileinput fileinput-new" data-provides="fileinput">
												<div class="image_preview_list" style="float: left;" id="imgs">
													<div class="fileinput-preview thumbnail image_preview_default" data-trigger="fileinput"
														style="width: 120px; height: 90px;"></div>
												</div>
												<div style="float: left; margin-left: 5px; padding-top: 23px;" class="addnewimg"
													id="f_span">
													<span class="btn btn-default btn-file" id="fir">
														<span class="fileinput-new" id="two">上传图片</span>
														<span class="fileinput-exists">Change</span>
														<input type="file" name="uploadFile" upload-file="detailImageUrl">
													</span>
													<div class="progress progress-striped active" role="progressbar" aria-valuemin="0"
														aria-valuemax="100" style="margin-bottom: 0px; margin-top: 10px;">
														<div class="progress-bar progress-bar-success" style="width: 0%;"></div>
													</div>
												</div>

											</div>


										</div>
									</form>

								</div>
								<div class="form-group  mrg-bt10">
									<label class="control-label col-md-3" style="line-height: 34px;">
										
										链接：
									</label>
									<div class="col-md-6">
										<textarea class="form-control" row=3 cols=15 name="linkurl" placeholder="请输入链接Url"
											style="resize: none" maxlength="200"></textarea>

									</div>
								</div>


							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
								<button type="button" class="btn btn-primary bt-save">保存</button>
							</div>
						</div>
					</form>

				</div>
			</div>
			<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
				<div class="container">
					<div class="row">
						<div id="content" class="col-lg-12">
							<!-- PAGE HEADER-->
							<div class="row">
								<div class="col-sm-12">
									<div class="page-header">
										<!-- STYLER -->

										<!-- /STYLER -->
										<!-- BREADCRUMBS -->
										<ul class="breadcrumb">
											<li>
												<i class="fa fa-home"></i>
												<a href="index.html">首页</a>
											</li>
											<li>
												<a href="#">商品管理</a>
											</li>
											<li>维护商品</li>
										</ul>
										<!-- /BREADCRUMBS -->

									</div>
								</div>
							</div>
							<!-- /PAGE HEADER -->
							<!-- SAMPLE -->
							<div class="row">
								<div class="col-md-12">
									<!-- BOX -->
									<div class="box border red" id="formWizard">
<input type="hidden" name="id"><input type="hidden" name="categoryId">

										<div class="box-body form">
											<form id="wizForm" action="#" class="form-horizontal">
											<input type="hidden" name="categoryId1">
											<input type="hidden" name="categoryId2">
											<input type="hidden" name="categoryId3">
												<div class="wizard-form">
													<div class="wizard-content">
														<ul class="nav nav-pills nav-justified steps">
															<li>
																<a href="#category" data-toggle="tab" class="wiz-step">
																	<span class="step-number">1</span>
																	<span class="step-name"><i class="fa fa-check"></i> 选择商品品类 </span>
																</a>
															</li>

															<li>
																<a href="#baseInfo" data-toggle="tab" class="wiz-step active">
																	<span class="step-number">2</span>
																	<span class="step-name"><i class="fa fa-check"></i> 编辑商品信息</span>
																</a>
															</li>
															<li>
																<a href="#imageDetail" data-toggle="tab" class="wiz-step">
																	<span class="step-number">3</span>
																	<span class="step-name"><i class="fa fa-check"></i> 编辑商品详情 </span>
																</a>
															</li>
														</ul>
														<div id="bar" class="progress  progress-sm active" role="progressbar">
															<div class="progress-bar progress-bar-warning"></div>
														</div>
														<div class="tab-content">
															
															<!-- 第一步 -->
															<div class="tab-pane" id="category">
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-4" style="text-align:center">一级分类</label>
																	<label class="control-label col-md-4" style="text-align:center">二级分类</label>
																	<label class="control-label col-md-4" style="text-align:center">三级分类</label>
																</div>
																<div class="form-group">
																	<div class="col-md-4">
																		<select class="form-control" multiple="" id="category1_select" style="height: 250px">
															 			<option>请选择一级分类</option>
															 			
															 		    </select>
																	</div>
																	<div class="col-md-4">
																		<select class="form-control" multiple="" id="category2_select" style="height: 250px">
												 						<option>请选择二级分类</option>												 						
												 						</select>
																	</div>
																	<div class="col-md-4">
																		<select class="form-control" multiple="" name="categoryId" id="category3_select" style="height: 250px">
												 			             <option value="">请选择三级分类</option>
												 			           
												 		                </select>
																	</div>
																</div>

															</div>
															<!-- /第一步 -->
															<!-- 第二步 -->
															<div class="tab-pane" id="baseInfo" style="height:740px">
															<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2">商品分类：</label>
																	<div class="col-md-8 inline" id="categoryName">
																			
																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>性别属性：</label>
																	<div class="col-md-8 inline">
																		<input type="checkbox" value="0" name="gender"/>男
																		<input type="checkbox" value="1" name="gender"/>女
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>商品名称：</label>
																	<div class="col-md-8 inline">
																		<input type="text" class="form-control width-50" name="productName"   placeholder="请输入商品名称" maxlength="50" />
																		<input type="hidden" name="id"/>
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>商品编码：</label>
																	<div class="col-md-8 inline">
																		<input type="text" class="form-control width-50" name="productCode"  placeholder="请输入商品编码" maxlength="50" />
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>商品原价：</label>
																	<div class="col-md-8 inline">
																		<input type="text" placeholder="原价" class="form-control width-50" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);"  name="productOriginalPrice" maxlength="10" />
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>商品售价：</label>
																	<div class="col-md-8 inline">
																		<input type="text" placeholder="销售价" class="form-control width-50" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);"  name="productSalePrice" maxlength="10" />
																		<span class="error-span"></span>
																	</div>
																</div>
																<!-- <div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>新客价：</label>
																	<div class="col-md-8 inline">
																		<input type="text" placeholder="新客价" readonly="readonly" class="form-control width-50" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);" value=0 name="newCustomPrice" maxlength="10" />
																		<span class="">价格大于0表示用户可以享受优惠价</span>
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2">会员价：</label>
																	<div class="col-md-8 inline">
																		<input type="text" placeholder="会员价" readonly="readonly" class="form-control width-50" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);" value=0 name="vipPrice" maxlength="10" />
																		<span class="">价格大于0表示用户可以享受会员价</span>
																		<span class="error-span"></span>
																	</div>
																</div> -->
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>商品单位：</label>
																	<div class="col-md-8 inline">
																		<input type="text" placeholder="请输入单位" maxlength="10"   class="form-control width-50" name="unitName" value="件"/>
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>颜色/规格：</label>
																	<div class="col-md-8 inline">
																		<input type="text" class="form-control width-50" maxlength="20"  name="shortName" placeholder="请输入颜色/规格" />
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>商品款式：</label>
																	<div class="col-md-8 inline">
																		<select id="group_select" name="group" style="width: 50%">
														  
														                </select>
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10 hide">
																	<label class="control-label col-md-2"><span class="required">*</span>商品品牌：</label>
																	<div class="col-md-8 inline">
																		<select id="brand_select" name="brand" style="width: 50%">
														  
														               </select>
																		<span class="error-span"></span>
																	</div>
																</div>
																<div class="form-group mrg-bt10" style="display: flex">
																	<label class="control-label col-md-2"><span class="required">*</span>商品类型：</label>
																	<div class="col-md-4 inline">
																		<select id="promotionType_select" name="promotionType" >																		 
																		  <option value="Ordinary">普通商品</option>
																		   <option value="Action">活动商品</option>
																		 
																		  
																		  </select>
																		  
																		<span class="error-span"></span>
																	</div>
																	<span class="" style="display:block;color:red" >展会商品请选择类型为活动商品</span>
																</div>
																<div class="form-group mrg-bt10" style="display:none">
																	<label class="control-label col-md-2"><span class="required">*</span>商品风格：</label>
																	<div class="col-md-8 inline">
																		<select id="style_select" name="style" style="width: 50%">
																	    
																	  </select>
																		<span class="error-span"></span>
																	</div>
																</div>
																
																<!-- <div class="form-group mrg-bt10" >
																	<label class="control-label col-md-2"><span class="required">*</span>所属店铺：</label>
																	<div class="col-md-8 inline">
																		<select id="supplier_select" name="supplier" style="width: 50%">
																	    
																	  </select>
																	 
																		<span class="error-span"></span>
																	</div>
																	
																</div> -->
																
															<!-- 	<div class="form-group mrg-bt10" >
																	<label class="control-label col-md-2"><span class="required">*</span>分享返利：</label>
																	<div class="col-md-8 inline">
																		<select id="shareRate_select" name="shareRate" style="width: 50%">
																			<option></option>
																	    	<option value="0.03">3%</option>
																	    	<option value="0.05">5%</option>
																	    	<option value="0.1">10%</option>
																	  	</select>
																		<span class="error-span"></span>
																	</div>
																</div> -->
																
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2">商品标签：</label>
																	<div class="col-md-8 inline">
																		<input type="text" class="form-control" value="" name="tags" style="width:50%"/>
																																	
																	</div>
																</div>
																<!-- <div class="form-group mrg-bt10">
																	<label class="control-label col-md-2">天猫ID：</label>
																	<div class="col-md-8 inline" style="display:flex;">
																		<input type="text" class="form-control" value="" name="tmallId" placeholder="请输入天猫商品ID" style="width:50%"/>
																		<a href="javascript:;" class="btn btn-warning bt-loadimage" style="margin-left:20px">加载图片</a>													
																	</div>
																</div> -->
																<div class="form-group mrg-bt10 creatSize" >
																	<label class="control-label col-md-2"><span class="required">*</span>尺码大小：</label>
																	<div class="col-md-8 sizelist">
																	  <div style="float:left">
																			<input type="text" class="form-control" style="width:100px;float:left" maxlength="10" name="sizeName" placeholder="尺码/大小" />
																			<a href="javascript:;" class="btn btn-primary bt-addSize">添加</a>
																		</div>

																	</div>
																</div>
																<div class="form-group mrg-bt10">
																	<label class="control-label col-md-2"><span class="required">*</span>SKU信息：</label>
																	<div class="col-md-9">
																		<table class="table table-bordered" id="skulist">
																			<thead>
																				<tr>
																				   <th style="display:none">id</th>
																					<th>尺码/大小</th>
																					<th>SKU编码</th>
																					<th>售价</th>
																					<!-- <th>新客价</th>
																					<th>会员价</th> -->
																					<th>原价</th>
																					<th>库存</th>
																					<th>操作</th>
																				</tr>
																			</thead>
																			<tbody>
																				
																			</tbody>
																		</table>
																	</div>
																</div>
																<div class="form-group mrg-bt10 uploadMainImage" style="line-height: 34px">
																	<label class="control-label col-md-2"><span class="required">*</span>商品图：</label>
																	<div class="col-md-9" style="line-height:34px;display:inline">
																		<label style="float:left">最多可以上传5张图片，建议尺寸：800*800px，大小不要超过300K。默认第一张为商品主图</label>
																		<div id="upload1" class="addnewimg" style="float:left; margin-left:5px;">
																			<span id="fir" class="btn btn-success btn-file">
																		    <span id="two" class="fileinput-new">上传图片</span>																			
																			<input type="file" upload-file="imageUrlProduct" multiple="" name="uploadFile">
																			</span>
																		</div>
																		<div style="margin-top: 10px;width: 100px" aria-valuemax="100" aria-valuemin="0" role="progressbar" class="progress progress-striped active">
																		<div style="width:0%;" class="progress-bar progress-bar-success"></div>
																	    </div>
																	</div>
																</div>

															
																	<div class="form-group mrg-bt10">
																	<label class="control-label col-md-1"></label>
																	<div class="col-md-9 dd" id="nestable2" style="margin-left:20px ">
																		<ol class="dd-list">
																			
																		</ol>
																	</div>
																
															</div>
															</div>

															<!-- /第二步 -->
															<!-- 第三步 -->
															<div class="tab-pane" id="imageDetail">
																<div class="form-group" style="line-height:34px">
																<label class=" col-md-7" style="line-height:34px;text-align:left">图文详情：建议图片宽度800px，大小不要超过300K。向左拖动图片进行排序，点击图片编辑链接</label>
																	<div id="upload2" class="addnewimg col-md-1" style=" margin-left:5px;">
																			<span id="fir" class="btn btn-success btn-file">
																		    <span id="two" class="fileinput-new">上传图片</span>																			
																			<input type="file" upload-file="detailUrlProduct" multiple="" name="uploadFile">
																			</span></div>
																			<div style="margin-top: 10px;width: 100px" aria-valuemax="100" aria-valuemin="0" role="progressbar" class="progress progress-striped active">
																		<div style="width:0%;" class="progress-bar progress-bar-success"></div>
																	    </div>
																	    <div class="fromImages col-md-1">
																	  <a data-toggle="modal" class="btn btn-warning">
																			<i class="fa  fa-plus-square-o"></i> 从图库选择
																		</a>
																	    </div>
																    
																</div>
																		  
																<div class="col-md-8">
								                             <!-- BOX -->
											
								
								                              <div class="col-md-9 dd" id="detailImage" style="margin-left:20px ">
																		<ol class="dd-list">
																			
																		</ol>
								</div>
									
								
								<!-- /BOX -->
								</div>
</div>
															<!-- /第三步 -->
														</div>
													</div>
													<div class="wizard-buttons" style="margin-top:80px;">
														<div class="row">
															<div class="col-md-12">
																<div class="col-md-offset-3 col-md-9">
																	<a href="javascript:;" class="btn btn-default prevBtn">
																		<i class="fa fa-arrow-circle-left"></i> 上一步
																	</a>
																	<a href="javascript:;" class="btn btn-primary nextBtn">
														下一步 <i class="fa fa-arrow-circle-right"></i>
													   </a>
																	<a href="javascript:;" class="btn btn-success submitBtn">
														保存 <i class="fa fa-arrow-circle-right"></i>
													   </a>
																</div>
															</div>
														</div>
													</div>
												</div>
											</form>
										</div>
									</div>
									<!-- /BOX -->
								</div>
							</div>
							<!-- /SAMPLE -->

							<div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
							</div>
						</div>
						<!-- /CONTENT-->
					</div>
				</div>
			</div>
		</section>
		<!--/PAGE -->
		<!-- JAVASCRIPTS -->
		<!-- Placed at the end of the document so the pages load faster -->
	
		<!-- JQUERY UI-->
		<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
		<!-- BOOTSTRAP -->
		<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
		<!-- SLIMSCROLL -->
	<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/jquery.slimscroll.min.js"></script>
	<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/slimScrollHorizontal.min.js"></script>
		<!-- BLOCK UI -->
		<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
		<!--bootbox-->
		<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
		<!-- AUTOSIZE -->
		<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
		<!-- spinner -->
		<script src="../../js/spinner/spin.js"></script>
		<!-- bootstrap-fileupload -->
		<script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
		<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
		<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script>
		<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>

		<!-- INPUT MASK -->
		<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>

		<!-- SELECT2 -->
		<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
		<!-- DATA TABLES -->
		<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
		<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>
		<!-- UNIFORM -->
		<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
		<!-- WIZARD -->
		<script src="../../js/bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>
		<!-- WIZARD -->
		<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
		<script src="../../js/jquery-validate/additional-methods.min.js"></script>
		<script src="../../js/bootstrap-wizard/form-wizard.js"></script>
		<!-- NESTABLE LISTS -->
		<script type="text/javascript" src="../../js/nestable/jquery.nestable.min.js"></script>
		<!-- COOKIE -->
		<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
		<!-- CUSTOM SCRIPT -->
		<script src="../../js/script.js"></script>
		
		<script src="../../js/Sortable.min.js"></script>
		<script>

			var AddProduct = function() {
			   var id=null,flag,groupId,productCode="",$mainDataTable;
			   var loadParentCategory=function(){
			   $.ajax({
						type: "get",
						url: App.getContextPath() + "admin/product/getParentCategory.do",
						async: true,
						success: function(result) {
							if (result.length > 0) {
								var data = eval(result);
								var option="";
								$.each(data, function(index, item) {
									option += "<option value='" + item.id + "'>" + item.categoryName + "</option>";
								});
								$("#category1_select").empty().append(option);
								$('#category1_select').change(function() {
									
								    loadCategoryById($('#category1_select').val()[0]);	
								    })		
							}
							}
							});
					
			   };
			   var loadCategoryById=function(id){
				   $.ajax({
							type: "get",
							url: App.getContextPath() + "admin/product/getCategoryByParentId.do",
							data:{parentId:id},
							async: true,
							success: function(result) {
								if (result.length > 0) {
									var data = eval(result);
									var option="";
									$.each(data, function(index, item) {
										option += "<option value='" + item.id + "'>" + item.categoryName + "</option>";
									});
									$("#category2_select").empty().append(option);								
									$("#category2_select").change(
									 function(){
										loadCategory3ById($('#category2_select').val()[0]);
									});
									$("#category2_select").get(0).selectedIndex = 0;
									$("#category2_select").trigger("change");
									
									}
								}
							});
			   		};
			   
			     var loadCategory3ById=function(id){
					   $.ajax({
								type: "get",
								url: App.getContextPath() + "admin/product/getCategoryByParentId.do",
								data:{parentId:id},
								async: true,
								success: function(result) {
									if (result.length > 0) {
										var data = eval(result);
										var option="";
										$.each(data, function(index, item) {
											option += "<option value='" + item.id + "'>" + item.categoryName + "</option>";
										});
										$("#category3_select").empty().append(option);
										}
										}
									
								});
			   };
			   
				var loadGroup = function() {
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/group/searchGroupList.do",
						async: true,
						success: function(result) {			
							if (result!=null) {
								var data = eval(result);
								var option = "<option></option>";
								$.each(data, function(index, item) {
									option += "<option value='" + item.id + "'>" + item.groupName + "</option>";
								});
								$("#group_select").empty().append(option).select2({
									placeholder: "选择款式"
								});
								$("#s2id_group_select").addClass("width_100");
							}
						}
					});
				};
				var loadBrand = function() {
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/brand/searchBrandList.do",
						async: true,
						success: function(result) {
							if (result!=null) {
								var data = eval(result);
								var option = "<option></option>";
								$.each(data, function(index, item) {
									option += "<option value='" + item.id + "'>" + item.brandName + "</option>";
								});
								$("#brand_select").empty().append(option).select2({
									placeholder: "选择品牌"
								});
								$("#s2id_brand_select").addClass("width_100");
							}
						}
					});
				};
				var loadStyle = function() {
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/style/searchStyleList.do",
						async: true,
						success: function(result) {
							if (result!=null) {
								var data = eval(result);
								var option = "<option></option>";
								$.each(data, function(index, item) {
									option += "<option value='" + item.id + "'>" + item.styleName + "</option>";
								});
								$("#style_select").empty().append(option).select2({
									placeholder: "选择风格"
								});
								$("#s2id_style_select").addClass("width_100");
							}
						}
					});
				};
				var loadSupplier = function() {
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/store/searchSupplierList.do",
						async: true,
						success: function(result) {
							if (result!=null) {
								var data = eval(result);
								var option = "<option value=''>选择店铺</option>";
								$.each(data, function(index, item) {
									option += "<option value='" + item.id + "'>" + item.supplierName + "</option>";
								});
								$("#supplier_select").empty().append(option).select2();
							}
						}
					});
				};
				//根据categoryId 获取父级信息
				var getParentsCategory=function(){					
					
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/product/getParentsByCategoryId.do",
						data:{categoryId:$("[name=categoryId]").val()},
						async: true,
						success: function(result) {
							if (result!=null) {
							 $("#category1_select").get(0).value = result[0].id;
 							 $("#category1_select").trigger("change");
 							 
 							 setTimeout(function(){
	 							 $("#category2_select").get(0).value = result[1].id;
	 							 $("#category2_select").trigger("change"); 	
	 							 setTimeout(function(){ 
 							  	$("#category3_select").get(0).value = result[2].id;
 							  },300);						  
 							 },300);
							}
						}
					});
					
				};
				
				
				//设置主图或者删除
				var handleHover=function(){
					$('.filter-content').hover(function() {
					var hoverContent = $(this).children('.hover-content');
					hoverContent.removeClass('fadeOut').addClass('animated fadeIn').show();
					}, function() {
						var hoverContent = $(this).children('.hover-content');
						hoverContent.removeClass('fadeIn').addClass('fadeOut').hide();
					});
				};
				//添加一个尺码
				var addSize = function() {
					var size = $("input[name=sizeName]").val().trim();
					if (size == "") {
						$.alert("请先设置尺码信息");
						return false;
					}
					var isExists=false;
					//判断尺码是否已经存在
					$(".table tbody tr").each(function(){
						if($(this).find("input:eq(0)").val()==size){
						  $.alert("输入尺码已经存在");
						 isExists=true;
						 return false;
						}
						  
						});
					if(isExists)return false;
					
					var salesPrice = $("input[name=productSalePrice]").val();
					var orgPrice = $("input[name=productOriginalPrice]").val();
					var newCustomPrice = $("input[name=newCustomPrice]").val();
					var vipPrice = $("input[name=vipPrice]").val();
					//根据productCode 自动生成skuCode
					var skuCode=$("[name=productCode]").val();
					if(skuCode!=""){
						var i=$("#skulist tbody tr").length+1;
						skuCode=skuCode+i;					
					}
				    addSizeHtml("",skuCode,size,salesPrice,orgPrice,0,"",newCustomPrice,"Valid",vipPrice);		
				};
				//上传商品图片
				var fileUpLoad = function() {
					$(".uploadMainImage").find('.progress-bar').css('width','0%');
					$(".uploadMainImage").find('.progress').hide();
					$("[upload-file=imageUrlProduct]").fileupload({
						url: App.getContextPath() + "admin/file/uploadImage.do",
						formData: {
							fileType: "ProductDetailImage,ProductListImage,ProductShoppingCartImage"
						},
						dataType: 'json',
						acceptFileTypes: /(\.|\/)(gif|jpe?g|png|JPG?g)$/i,
						iframe: true,
						maxNumberOfFiles: 5,
						autoUpload: true,
						start:function(e) {		    	
					    	$(".uploadMainImage").find('.progress').fadeIn(300);					    	
					    	return true;
				    	},				
						done: function(e, data) {							
							var result = data.result;
							if(result.message!=""){
								$.alert(result.message)
								return false;
							}else{
					        addMainImageHtml(result.fileUrl,"");
					        $('#nestable2').nestable({maxDepth: 1});
							}
						},						
					    progressall: function (e, data) {					    	
				            var progress = parseInt(data.loaded / data.total * 100, 10);
				           $(".uploadMainImage").find('.progress-bar').css('width',progress + '%');
				        }
					}).on('fileuploaddone',function(e,data) {
							$(".uploadMainImage").find(".progress").fadeOut(300);
					
					});
				};
				
				//上传商品详情页图片
				var detailFileUpLoad = function() {
					$("#imageDetail").find('.progress-bar').css('width','0%');
					$("#imageDetail").find('.progress').hide();
					$("[upload-file=detailUrlProduct]").fileupload({
						url: App.getContextPath() + "admin/file/uploadImage.do",
						formData: {
							fileType: "ProductDetailImage"
						},
						dataType: 'json',
						acceptFileTypes: /(\.|\/)(gif|jpe?g|png|JPG?g)$/i,
						iframe: true,
						start:function(e) {	
							$(".fromImages").hide();
					    	$("#imageDetail").find('.progress').fadeIn(300);					    	
					    	return true;
				    	},						
						autoUpload: true,
						done: function(e, data) {
							
							var result = data.result;
							if(result.message!=""){
								$.alert(result.message)
								$(".fromImages").show();
								return false;
							}else{
					        addDetailHtml(result.fileUrl);
					        setTimeout(function(){$(".fromImages").show();},200);
					        
							}
						},						
					    progressall: function (e, data) {					    	
				            var progress = parseInt(data.loaded / data.total * 100, 10);
				           $("#imageDetail").find('.progress-bar').css('width',progress + '%');
				        }
					}).on('fileuploaddone',function(e,data) {
							$("#imageDetail").find(".progress").fadeOut(300);
					
					});
				};
				
				//保存商品
				var saveProduct=function(e){

					e.preventDefault();
				  if($("#imageDetail").find("img").length==0)
				  {
				  	$.alert("请至少上次一张商品详情图");
				  	return false;
				  }
				  var isExists=false;
				  var sizeArray=[];
					
				   $.blockUI();
				  var flag=$.getUrlParam("flag");
				  var p={};				   
				  if(flag!="group")
				  p.id=$("input[name=id]").val();
				  p.productCode=$("input[name=productCode]").val();
				  p.productName=$("input[name=productName]").val();
				  p.productOriginalPrice=$("input[name=productOriginalPrice]").val();
				  p.productSalePrice=$("input[name=productSalePrice]").val();
				  /* p.newCustomPrice=$("input[name=newCustomPrice]").val();
				  p.vipPrice=$("input[name=vipPrice]").val(); */
				  p.newCustomPrice=0;
				  p.vipPrice=0;
				  p.shortName=$("input[name=shortName]").val();
				  p.brandId=2;//$("#brand_select").val();
				  p.groupId=$("#group_select").val();
				  p.categoryId=$("#category3_select").val()[0];
				  p.supplierId=$("#supplier_select").val();
				  p.styleId=1;//$("#style_select").val();
				  p.unitName=$("input[name=unitName]").val();
				  p.promotionType=$("#promotionType_select").val();
				  /* p.tmallId=$("[name=tmallId]").val(); */
				  p.shareRate=$("[name=shareRate]").val();
				  /* var tags="";
				  $("[name=tags]:checked").each(function(){
					  tags=$(this).val();
				  }); */
				  p.tags=$("[name=tags]").val();
				  p.productImages = [];
				  p.ygSkus = [];
				  p.ygSkus.stock = [];
					var gender = "";
					if($("[name=gender]:checked").length == 1){
						gender = $("[name=gender]:checked").val();
					}else {
						gender = "0,1";
					}
					p.gender = gender;
				  //获取主图
					$("#nestable2").find("img").each(function(index,item){
						var img = {};
						img.imagePath  =$(this).src;
						if(index==0)
							img.isMain=1;
						else
							img.isMain=0;
						img.id=$(this).attr("pid");
						img.sortNum=index++;
						img.imagePath=$(this).attr("src");
						p.productImages.push(img);
						
					});
					//获取sku
					var i=0;//sku状态个数统计
					$("#skulist tbody tr").each(function(){
						var sku = {};
						if(flag!="group")
						sku.id=$(this).find("td:eq(0)").html();
						sku.skuCode=$(this).find("input[name=skuCode]").val();
						sku.sizeName=$(this).find("input:eq(0)").val().trim();
						sku.salesPrice=$(this).find("input[name=salesPrice]").val();
						sku.sourceSalesPrice=$(this).find("input[name=orgPrice]").val();	
						sku.newCustomPrice=0;
						sku.vipPrice=0;	
						//sku.newCustomPrice=$(this).find("input[name=newCustomPrice]").val();
						//sku.vipPrice=$(this).find("input[name=vipPrice]").val();	
						sku.status=$(this).find(".bt-del-size").attr("status");
						if(sku.status=="Valid")i++;
						var stock={};						
						stock.id=$(this).find("input[name=stockNum]").attr("id");
						stock.skuCode=sku.skuCode;
						stock.amount=$(this).find("input[name=stockNum]").val();
						sku.stock=stock;
						p.ygSkus.push(sku);
						
					});					
					//获取详情图
					var detailImg=[];
					$("#imageDetail").find("img").each(function(){
						var path=$(this).attr("src");
						var link=$(this).attr("linkurl");
						if(link!="")path=path+";"+link;
						detailImg.push(path);						
					});
					p.detailImagePath=detailImg.toString();
					///判断sku 的状态是否是有效的
					if(i==0){
						$.unblockUI();
						$.alert("请添加有效的SKU");
						return false;
					}
				  $.ajax({
						type: "post",
						url: App.getContextPath() + "admin/product/saveProduct.do",
						data:$.param({product:JSON.stringify(p),productCode:productCode}),
						async: true,
						success: function(result) {
						 $.unblockUI();
						if(result.type=="error"){
							$.alert(result.extra);}
						else{
							$.alert("保存成功");
							
							location.href="product_list.html";
							}	
						}					
					});
				}
				
				//根据分组获取产品信息
				var getProductByGroup=function(groupId){
				$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/product/getProductByGroupId.do",
						data:{groupId:groupId},
						async: true,
						success: function(result) {
							setProduct(result);
							$("input[name=shortName]").val("");
							$("input[name=productName]").val("");
							}						
					});
				};
				
				//根据产品id 获取产品信息
				var getProductInfo=function(productId){
				$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/product/getProductById.do",
						data:{id:productId},
						async: true,
						success: function(result) {
							setProduct(result);
							}						
					});
				};
				
				var setProduct=function(p){	
				 if(flag=="edit")
				  $("input[name=id]").val(p.id);
				  $("input[name=categoryId]").val(p.categoryId);
				   getParentsCategory();//设置分类
				  $("input[name=productCode]").val(p.productCode);
				  $("input[name=productCode]").attr('readonly', 'readonly');
				  productCode=p.productCode;
				  $("input[name=productName]").val(p.productName);
				  $("input[name=productOriginalPrice]").val(p.productOriginalPrice);
				  $("input[name=productSalePrice]").val(p.productSalePrice);
				  /* $("input[name=newCustomPrice]").val(p.newCustomPrice);
				  $("input[name=vipPrice]").val(p.vipPrice); */
				  $("input[name=shortName]").val(p.shortName);
				  /* $("[name=tmallId]").val(p.tmallId); */
				  $("#brand_select").select2("val",p.brandId);
				  $("#group_select").select2("val",p.groupId);
				  $("#category3_select").select2("val",p.categoryId);
				  $("#categoryName").html(p.categoryName);
				  if(flag!="copy"){
					  $("#supplier_select").select2("val",p.supplierId);
					  $("#promotionType_select").select2("val",p.promotionType);
					  $("#shareRate_select").select2("val",p.shareRate==null?"":p.shareRate);
				  }
				  $("#style_select").select2("val",p.styleId);
				  $("input[name=unitName]").val(p.unitName);
				  $("[name=tags]").val(p.tags);
				  /* if(p.tags!=null){
					  var arr=p.tags.split(",");
					  for(var i=0;i<arr.length;i++){
						  $("[name=tags]").each(function(){
								if($(this).val()==arr[i])
									$(this).attr("checked",true);
									
							});	 						  					  
					  }
				  } */
				if(p.gender != null){
					if(p.gender == "0"){
						$("[name=gender]").eq(0).attr("checked",'true');
					}else if(p.gender == '1') {
						$("[name=gender]").eq(1).attr("checked",'true');
					}else {
						$("[name=gender]").attr("checked",'true');
					}
				}

				  //根据sku 设置尺码
				   //对商品尺码排序
				  p.ygSkus.sort(function(a,b){
            				return a.id-b.id});
            				
				 $.each(p.ygSkus, function(index,item) {				
				 	addSizeHtml(item.id,item.skuCode,item.sizeName,item.salesPrice,item.sourceSalesPrice,item.stock.amount,item.stock.id,item.newCustomPrice,item.status,item.vipPrice);			 	
				 });
				 //对商品主图排序
				  p.productImages.sort(function(a,b){
            				return a.sortNum-b.sortNum});
				  //设置商品主图
				  $.each(p.productImages, function(index,item) {
				  	addMainImageHtml(item.imagePath,item.id);				  	
				  });
				  
				  //设置商品详情图 
				  $.each(p.detailImagePath.split(','), function(index,item) {
				  	addDetailHtml(item);				  	
				  });	
				  
				  
				  if(flag=="group")
				  {
				    $("input[name=shortName]").val("");
							$("input[name=productName]").val("");
							$("[name=productCode]").val("");
							$("input[name=id").val("");
							//$("#nestable2").find("li").remove();
							$(".media-list").html("");
							$("[name=skuCode]").val("");
							$("#skulist").find("tbody").empty();
				  }	
				  setTimeout(function(){
					  $('#nestable2').nestable();	
				  },3000);
				    
				  
				}
				
				//添加Size
				var addSizeHtml=function(skuid,skuCode,size,salesPrice,orgPrice,stockNum,stockid,newCustomPrice,skustatus,vipPrice){
					/* var sizehtml = '<div class="alert alert-block alert-info fade in input-size" style="height: 40px;margin-bottom:0px;width:auto;">' +
						'<a aria-hidden="true" href="#" data-dismiss="alert" class="bt-del-size close">×</a>' +
						'<p style="min-width:80px"><strong>' + size + '</strong></p></div>';
					$(".sizelist").append(sizehtml); */
					var r=skustatus=="Delete"?"readonly":"";
					var readOnly=skuid==""&&id==null?"readonly":"";
					    readOnly = flag=="group"?"readonly":"";
					var statutxt="删除";
					var statusclass="btn-danger";
					if(skuid!=""){
						statutxt=skustatus=="Delete"?"启用":"禁用";
						statusclass=skustatus=="Delete"?"btn-warning":"btn-danger";
					}
					//添加一个table 行
					var trhtml = '<tr status="Valid"><td style="display:none">'+skuid+'</td><td><input type="text" class="form-control" '+r+' '+readOnly+' maxlength=50 value="'+size+'"/></td><td><input type="text" name="skuCode" '+r+' '+readOnly+' class="form-control" style="width:100px;" maxlength="10" placeholder="SKU编码" value="'+skuCode+'"/></td>' +
						'<td><input type="text" name="salesPrice" class="form-control" '+r+' style="width:60px;" value="' + salesPrice + '" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);" maxlength="10" placeholder="售价"/></td>' +
						//'<td><input type="text" name="newCustomPrice"  class="form-control" '+r+' style="width:60px;" value="' + newCustomPrice + '" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);" maxlength="10" placeholder="新客价"/></td>' +
						//'<td><input type="text" name="vipPrice"  class="form-control" '+r+' style="width:60px;" value="' + vipPrice + '" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);" maxlength="10" placeholder="会员价"/></td>' +
						'<td><input type="text" name="orgPrice" class="form-control" '+r+' style="width:60px;" value="' + orgPrice + '" maxlength="10" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);" placeholder="原价"/></td>' +
						'<td><input type="text" name="stockNum"class="form-control" '+r+' style="width:60px;" maxlength="10" onkeypress="return $.IsNum(event);" onblur="return $.IsNaN(this);" placeholder="库存" value="'+stockNum+'" id="'+stockid+'"/></td><td><a class="btn '+statusclass+' bt-del-size" status='+skustatus+' href="javascript:;">'+statutxt+'</a></td></tr>';
					$(".table tbody").append(trhtml);
					$("input[name=sizeName]").val('');
					//设置内容的高度
					$(".wizard-content").css("height", $(".wizard-content").height() + 52);
					//删除size 时将数据行删除
					$(".bt-del-size").unbind("click").bind("click",function(){
						var s=$(this).closest("tr").find("td:eq(0)").html();
						if(s.length>0){								
								if($(this).html()=="禁用"){
								 $(this).closest("tr").find("input").attr("readonly","readonly");
								 $(this).html("启用").removeClass("btn-danger").addClass("btn-warning");
								 $(this).attr("status","Delete");
								}
								else{
								$(this).closest("tr").find("input").removeAttr("readonly");
								$(this).html("禁用").removeClass("btn-warning").addClass("btn-danger");
								 $(this).attr("status","Valid");
								}
								 
							}else{							
								$(this).closest("tr").remove();
								
							}
							
						
					});
					//注册SKU验证事件
					$("[name=skuCode]").unbind("blur").bind("blur",checkSKUCode);
				};
				
				//添加商品主图
				var addMainImageHtml=function(url,id){
							var i="imgage"+($('#nestable2').find(".dd-list").find("li").length+1);
						var imgs='<li class="dd-item filter-content" data-id="'+i+'"><img class="dd-handle" width="180px" height="180px" src="'+url+'" pid="'+id+'"/>'+
							'<div class="hover-content"><a class="btn btn-danger hover-link colorbox-button btn-del-image"  title="删除"><i class="fa fa-times fa-1x"></i></a></div></li>';
						$('#nestable2').find(".dd-list").append(imgs);
						
						 handleHover();
						 $(".btn-setMain").unbind("click").bind("click",function(){
						 //已经设置主图的取消设置
						     $(".bt-main").hide();
						     $(this).prev().show();$(this).hide();$(this).next().hide();
						 });
						  $(".btn-del-image").click(function(){
						    $(this).closest("li").remove();
						     $("#upload1").show();
						  });
						  
						  //如果当前图片个数已经达到5个隐藏上传按钮
						  if($('#nestable2').find(".dd-list li").length==5&&flag!="group")
						  {
						     $("#upload1").hide();
						  }
				};
				//添加商品详情图
				var i=0;
				var addDetailHtml=function(url){
					i++;
					var urlArr=url.split(";"),linkUrl="";
					if(urlArr.length>1)linkUrl=urlArr[1];					
					var imgUrl=urlArr[0];
					var id="image"+i;
						var imgs='<li class="dd-item filter-content" data-id="'+id+'"><img class="dd-handle" id="'+id+'" width="414px" src="'+imgUrl+'" linkurl="'+linkUrl+'"/><div class="hover-content"><a class="btn btn-success bt-edit hover-link"><i class="fa fa-edit fa-1x"></i></a><a class="btn btn-danger hover-link colorbox-button btn-del-image"  title="删除"><i class="fa fa-times fa-1x"></i></a></div></li>';
						$('#detailImage').find(".dd-list").append(imgs);
						$('#detailImage').find(".dd-list").on("click",".btn-del-image",function(){
						  $(this).closest("li").remove();
						});
						$('#detailImage').find(".dd-list").find(".filter-content").hover(function() {						
							var hoverContent = $(this).children('.hover-content');
							hoverContent.removeClass('fadeOut').addClass('animated fadeIn').show();							
								}, function() {
									var hoverContent = $(this).children('.hover-content');
									hoverContent.removeClass('fadeIn').addClass('fadeOut').hide();
								});
						$('#detailImage').nestable();
						$("#detailImage").find(".bt-edit").unbind("click").click(function(){
							id=$(this).closest("li").find("img").attr("id");
							var url=$(this).closest("li").find("img").attr("src");
							var link=$(this).closest("li").find("img").attr("linkurl");
							var imageId=$(this).closest("li").find("img").attr("id");
							
							$("#editImage").find("[name='imagePath']").val(url);
							$("#editImage").find(".image_preview_default").empty().append("<img src='"+url+"'/>");

							$("[name=linkurl]").val(link);
							$(".progress").hide();
							upLoadImg();
							$(".bt-save").unbind("click").click(function(){
								url=$("#editImage").find("[name='imagePath']").val();
								link=$("#editImage").find("[name='linkurl']").val();
								
								$("#"+id).attr("src",url);
								$("#"+id).attr("linkurl",link);
								$("#editImage").modal("hide");
							});
							$("#editImage").modal("show");
							
						});
				};
				
				//检验商品编码
				var checkProductCode=function(){
					var tempProductCode=$("[name=productCode]").val();
				 if(tempProductCode!=""){				 
					 $.ajax({
							type: "get",
							url: App.getContextPath() + "admin/product/checkProductCode.do",
							data:{productCode:tempProductCode,id:$("[name=id]").val()},
							async: true,
							success: function(result) {
								if(result==true){
								 $.alert("商品编码"+$("[name=productCode]").val()+"已存在");
								 $("[name=productCode]").val(productCode);
								 return false;							
								}
								return true;
							}						
						});
				 }
				}
				var getSizeList=function(){
					$(".table tbody").html("");
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/product/getSkuList.do",
						data:{productCode:$("input[name=productCode]").val()},
						async: true,
						success: function(result) {
							if(result.length>0){
								var salesPrice = $("input[name=productSalePrice]").val();
								var orgPrice = $("input[name=productOriginalPrice]").val();
								var newCustomPrice = $("input[name=newCustomPrice]").val();
								var vipPrice = $("input[name=vipPrice]").val();
								$.each(result,function(index,item){	
									
								    addSizeHtml("",item.skuCode,item.sizeName,salesPrice,orgPrice,0,"",newCustomPrice,"Valid",vipPrice);	
								})
								//checkProductCode();
							 							
							}else{
								 $.alert("商品编码"+$("[name=productCode]").val()+"不存在");
								 return false;
							}
						}						
					});
					
				}
				//检验SKU编码
				var checkSKUCode=function(){
				var that=$(this);
				 if($(this).val()!=""){				 
					 $.ajax({
							type: "get",
							url: App.getContextPath() + "admin/product/checkSkuCode.do",
							data:{skuCode:$(this).val(),id:$(this).closest("tr").find("td:eq(0)").html()},
							async: true,
							success: function(result) {
								if(result==true){
								 $.alert("SKU编码 "+$(that).val()+" 已存在");	
								 $(that).val("");							
								 return false;							
								}else{return true};
							}						
						});
				 }
				}
				//商品详情图的编辑
				var upLoadImg = function() {

					$("[upload-file=detailImageUrl]")
							.fileupload(
									{
										url : App.getContextPath()
												+ "admin/file/uploadFile.do",
										formData: {
													fileType: "ProductDetailImage"
												},
										dataType : 'json',
										acceptFileTypes : /(\.|\/)(gif|jpe?g|png|JPG?g)$/i,
										iframe : true,
										start : function(e) {
											$('.progress').fadeIn(300);
											return true;
										},
										autoUpload : true,
										done : function(e, data) {
											var result = data.result;
											var $tr = $(this).closest("form");
											$tr
													.find("[hidden-image]")
													.append(
															"<input type='hidden' name='imagePath' value='" + result.fileUrl+"' />");
											$tr.find(".image_preview_default").html(
													"<img src='"+result.fileUrl+"' />");
											
											

										},
										progressall : function(e, data) {
											var progress = parseInt(data.loaded
													/ data.total * 100, 10);
											$('.progress .progress-bar').css('width',
													progress + '%');
										}
									}).on('fileuploaddone', function(e, data) {
								$(".progress").fadeOut(300);

							});
				}
				
				//获取图片库
				var getImagesList=function(){
				          var url=App.getContextPath()+"admin/images/searchImages.do";
				          var type=$("#ImagesType_select").val();
				            if(type!=-1&&type!=null)
			                  url+="?q="+type;
				            
						       if($mainDataTable){
						           $mainDataTable.api().ajax.url(url).load();	   		
					   		       return;	
						        }
					           var dtSetting = $.dataTableSetting({					
										"ajaxSource" :url,
										"serverSide" : true,
										"bFilter" : false,// 去掉搜索框
										"bLengthChange" : true,// 每页显示数量							
										"sScrollX":"100%",
										"sScrollXInner": "100%",
										"iDisplayLength": 10,
										
										"bSort" : false,					
										"aoColumns" : [{
											"mDataProp" : "imagePath",
											"sTitle" : "图片",
											"width" : "200px",
											"class":"imagePath",
											"render":function(data, type, row){							
											    return "<a target='_blank' href='"+row.imagePath+"'><img width='30px' height='30px' src="+(row.imagePath)+"></a>";
											}
										},
										{
											"mDataProp" : "tags",
											"sTitle" : "图片类型",
											"class":"tags",
											"width" : "200px",
											"render":function(data, type, row){		
												if(row.tags=="QuantityCheck")
													return "质检报告";
												if(row.tags=="Size")
													return "尺码表";
												return row.tags;
																		   
											}
										}																
										, {
											"sTitle" : "操作",
											"width" : "100px",
											"render":function(data, type, row){											   
										         return "<a class='btn btn-danger btn-xs btn-width bt-insert' style='width:60px;margin-bottom:5px;' href='javascript:;'>使用</a>";
				       
											   }	
										
											
										}]
									});
								
							      $mainDataTable = $("#db_Images_list").dataTable(dtSetting);
				        
				}
				
				var loadTmallImage=function(){
					$.blockUI();
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/product/getProductImagesByTmall.do",
						data:{tid:$("[name=tmallId]").val()},
						async: true,
						success: function(result) {
							$.unblockUI();
							$("#nestable2").find("li").remove();
							  //设置商品主图
							  $.each(result.productImages, function(index,item) {
							  	var url=item.imagePath.indexOf("http")<0?"http:"+item.imagePath:item.imagePath;
								  addMainImageHtml(url,"");				  	
							  });
							  $("#detailImage").find("li").remove();
							  
							  //设置商品详情图 
							  $.each(result.detailImagePath.split(','), function(index,item) {
							  	addDetailHtml(item);				  	
							  });
							
						}						
					});
				}
				
				return {
					init: function() {
						  flag=$.getUrlParam("flag");
						  id=$.getUrlParam("id")||null;
						  groupId=$.getUrlParam("groupId");
					    loadParentCategory();
						loadGroup();
						//loadBrand();
						//loadStyle();
						//loadSupplier();
						//根据天猫Id获取商品图片
						$(".bt-loadimage").click(function(){
								if($("[name=tmallId]").val().trim().length==0)
									return false;
								if(id!=null){
									$.confirm("重新加载图片会清楚掉之前所有图片",function(){
										loadTmallImage();
									});
									
								}else{
									loadTmallImage();
								}				
						});
						
						$("#style_select").select2();
						$("#promotionType_select").select2({
							placeholder: "选择商品类型"
						});
						$("#s2id_promotionType_select").addClass("width_100");
					/* 	$("#supplier_select").select2({
							placeholder: "选择所属店铺"
						});
						$("#s2id_supplier_select").addClass("width_100"); */
						$("#shareRate_select").select2({placeholder: "选择返利率"});
						$(".uniform").uniform();
						App.init();
						FormWizard.init();
						$(".bt-addSize").click(addSize);
					
						 fileUpLoad();
						
						 detailFileUpLoad();
						 $('#formWizard .submitBtn').click(saveProduct).hide();
						 if(id)$(".creatSize").show();
						 $("[name=productCode]").blur(function(){
							 
							 if(id==null){
								 checkProductCode();
							 }
							
						 });
						
						  if(flag=="edit"||flag=="group"||flag=="copy"){	
						   getProductInfo(id);
						 }
						 
						 //回车事件注册在添加尺码上 
						 document.onkeydown = function(e){
			    		    var ev = document.all ? window.event : e;
			    		    if(ev.keyCode==13) {    		    	
			    		        $(".bt-addSize").trigger("click");
			    		     }
			    		};
						 $("input[name=productName]").focus();
						 $("[name=productSalePrice]").blur(function(){
							 $("#skulist").find("tbody tr").find("[name=salesPrice]").val($(this).val());
							 
						});
						 $("[name=productOriginalPrice]").blur(function(){
							 $("#skulist").find("tbody tr").find("[name=orgPrice]").val($(this).val());
							 
						});
						/*  $("[name=newCustomPrice]").blur(function(){
							 $("#skulist").find("tbody tr").find("[name=newCustomPrice]").val($(this).val());
							 
						});
						 $("[name=vipPrice]").blur(function(){
							 $("#skulist").find("tbody tr").find("[name=vipPrice]").val($(this).val());
							 
						}); */
						
						 $("#ImagesType_select").select2();
						 //显示图库
						 $(".fromImages").click(function(){
							 $("#box-config").modal("show");
							 setTimeout(function(){
								 getImagesList();
								 $("#db_Images_list").off("click").on("click",".bt-insert",function() {								
									 var tr = $(this).closest("tr");								
									 addDetailHtml($(tr).find(".imagePath").find("img").attr("src"));
									 $(this).hide();
								 });
								 $(".searchImages").click(getImagesList); 
							 },200)
							
							 
						 });
					}
				}
			}();
			$(function() {
			    $("#header").load("../head.html");
			  	AddProduct.init();
			});
		</script>

		<!-- /JAVASCRIPTS -->
	</body>

</html>